home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / TEST_NOD.C < prev    next >
C/C++ Source or Header  |  1992-08-20  |  8KB  |  184 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <test.h>
  14. #include <cool/String.h>
  15. #include <cool/N_Node.h>
  16. #include <cool/D_Node.h>
  17.  
  18. #include <cool/N_Node.C>
  19. #include <cool/D_Node.C>
  20. #include <cool/Vector.C>
  21.  
  22. void test_NN () {
  23.   CoolN_Node<short,3> n0;
  24.   TEST ("CoolN_Node<short,3> n0", n0.is_leaf(), TRUE);
  25.   TEST ("n0.set(4)", (n0.set(short(4)), n0.get()), 4);
  26.   CoolN_Node<short,3>& n1 = *(new CoolN_Node<short,3>(short(3)));
  27.   TEST ("CoolN_Node<short,3> n1(3)", n1.is_leaf(), TRUE);
  28.   TEST ("n1.get()", n1.get(), 3);
  29.   CoolN_Node<short,3>& n2 = *(new CoolN_Node<short,3>(n1));
  30.   TEST ("CoolN_Node<short,3> n2(n1)", (n1.get() == n2.get()), 1);
  31.   CoolN_Node<short,3>& n3 = *(new CoolN_Node<short,3>(short(5)));
  32.   TEST ("CoolN_Node<short,3> n3(5)", n3.is_leaf(), TRUE);
  33.   TEST ("n3.get()", n3.get(), 5);
  34.   TEST ("n1.set(4)", (n1.set(short(4)), n1.get()), 4);
  35.   TEST ("n0[0] = &n1", (n0[0] = &n1, (n0[0] == &n1)), 1);
  36.   TEST ("n0.is_leaf()", n0.is_leaf(), FALSE);
  37.   TEST ("n0.insert_before(n2,0)", n0.insert_before(n2,0), TRUE);
  38.   TEST ("n0[0] == &n2", (n0[0] == &n2), 1);
  39.   TEST ("n0[1] == &n1", (n0[1] == &n1), 1);
  40.   TEST ("n0.insert_after(n3,0)", n0.insert_after(n3,0), TRUE);
  41.   TEST ("n0[0] == &n2", (n0[0] == &n2), 1);
  42.   TEST ("n0[1] == &n3", (n0[1] == &n3), 1);
  43.   TEST ("n0[2] == &n1", (n0[2] == &n1), 1);
  44.  
  45.   CoolN_Node<CoolString,3> n8;
  46.   TEST ("CoolN_Node<CoolString,3> n", n8.is_leaf(), TRUE);
  47.   TEST ("n8.set(CoolString(\"AAA\"))", (n8.set(CoolString("AAA")), strcmp (n8.get(), "AAA")), 0);
  48.   CoolN_Node<CoolString,3>& n9 = *(new CoolN_Node<CoolString,3>(CoolString("BBB")));
  49.   TEST ("CoolN_Node<CoolString,3> n9(CoolString(\"BBB\"))", n9.is_leaf(), TRUE);
  50.   TEST ("n9.get()", strcmp (n9.get(), "BBB"),0);
  51.   CoolN_Node<CoolString,3>& n10 = *(new CoolN_Node<CoolString,3>(n9));
  52.   TEST ("CoolN_Node<CoolString,3> n10(n9)", strcmp (n9.get(), n10.get()), 0);
  53.   CoolN_Node<CoolString,3>& n11 = *(new CoolN_Node<CoolString,3>(CoolString("CCC")));
  54.   TEST ("CoolN_Node<CoolString,3> n11(CoolString(\"CCC\"))", n11.is_leaf(), TRUE);
  55.   TEST ("n11.get()", strcmp (n11.get(), "CCC"), 0);
  56.   TEST ("n9.set(CoolString(\"DDD\"))", (n9.set(CoolString("DDD")), strcmp (n9.get(), "DDD")), 0);
  57.   TEST ("n8[0] = &n9", (n8[0] = &n9, (n8[0] == &n9)), 1);
  58.   TEST ("n8.is_leaf()", n8.is_leaf(), FALSE);
  59.   TEST ("n8.insert_before(n10,0)", n8.insert_before(n10,0), TRUE);
  60.   TEST ("n8[0] == &n10", (n8[0] == &n10), 1);
  61.   TEST ("n8[1] == &n9", (n8[1] == &n9), 1);
  62.   TEST ("n8.insert_after(n11,0)", n8.insert_after(n11,0), TRUE);
  63.   TEST ("n8[0] == &n10", (n8[0] == &n10), 1);
  64.   TEST ("n8[1] == &n11", (n8[1] == &n11), 1);
  65.   TEST ("n8[2] == &n9", (n8[2] == &n9), 1);
  66. }
  67.  
  68. void test_DN () {
  69.   CoolD_Node<short,3> d0;
  70.   TEST ("CoolD_Node<short,3> d0", d0.is_leaf(), TRUE);
  71.   TEST ("d0.set(4)", (d0.set(short(4)), d0.get()), 4);
  72.   CoolD_Node<short,3>& d1 = *(new CoolD_Node<short,3>(short(3)));
  73.   TEST ("CoolD_Node<short,3> d1(3)", d1.is_leaf(), TRUE);
  74.   TEST ("d1.get()", d1.get(), 3);
  75.   CoolD_Node<short,3>& d2 = *(new CoolD_Node<short,3>(d1));
  76.   TEST ("CoolD_Node<short,3> d2(d1)", (d1.get() == d2.get()), 1);
  77.   CoolD_Node<short,3>& d3 = *(new CoolD_Node<short,3>(short(5)));
  78.   TEST ("CoolD_Node<short,3> d3(5)", d3.is_leaf(), TRUE);
  79.   TEST ("d3.get()", d3.get(), 5);
  80.   TEST ("d1.set(4)", (d1.set(short(4)), d1.get()), 4);
  81.   TEST ("d0[0] = &d1", (d0[0] = &d1, (d0[0] == &d1)), 1);
  82.   TEST ("d0.is_leaf()", d0.is_leaf(), FALSE);
  83.   TEST ("d0.insert_before(d2,0)", d0.insert_before(d2,0), TRUE);
  84.   TEST ("d0[0] == &d2", (d0[0] == &d2), 1);
  85.   TEST ("d0[1] == &d1", (d0[1] == &d1), 1);
  86.   TEST ("d0.insert_after(d3,0)", d0.insert_after(d3,0), TRUE);
  87.   TEST ("d0[0] == &d2", (d0[0] == &d2), 1);
  88.   TEST ("d0[1] == &d3", (d0[1] == &d3), 1);
  89.   TEST ("d0[2] == &d1", (d0[2] == &d1), 1);
  90.  
  91.   CoolD_Node<CoolString,3> d8;
  92.   TEST ("CoolD_Node<CoolString,3> n", d8.is_leaf(), TRUE);
  93.   TEST ("d8.set(CoolString(\"AAA\"))", (d8.set(CoolString("AAA")), strcmp (d8.get(), "AAA")), 0);
  94.   CoolD_Node<CoolString,3>& d9 = *(new CoolD_Node<CoolString,3>(CoolString("BBB")));
  95.   TEST ("CoolD_Node<CoolString,3> d9(CoolString(\"BBB\"))", d9.is_leaf(), TRUE);
  96.   TEST ("d9.get()", strcmp (d9.get(), "BBB"),0);
  97.   CoolD_Node<CoolString,3>& d10 = *(new CoolD_Node<CoolString,3>(d9));
  98.   TEST ("CoolD_Node<CoolString,3> d10(d9)", strcmp (d9.get(), d10.get()), 0);
  99.   CoolD_Node<CoolString,3>& d11 = *(new CoolD_Node<CoolString,3>(CoolString("CCC")));
  100.   TEST ("CoolD_Node<CoolString,3> d11(CoolString(\"CCC\"))", d11.is_leaf(), TRUE);
  101.   TEST ("d11.get()", strcmp (d11.get(), "CCC"), 0);
  102.   TEST ("d9.set(CoolString(\"DDD\"))", (d9.set(CoolString("DDD")), strcmp (d9.get(), "DDD")), 0);
  103.   TEST ("d8[0] = &d9", (d8[0] = &d9, (d8[0] == &d9)), 1);
  104.   TEST ("d8.is_leaf()", d8.is_leaf(), FALSE);
  105.   TEST ("d8.insert_before(d10,0)", d8.insert_before(d10,0), TRUE);
  106.   TEST ("d8[0] == &d10", (d8[0] == &d10), 1);
  107.   TEST ("d8[1] == &d9", (d8[1] == &d9), 1);
  108.   TEST ("d8.insert_after(d11,0)", d8.insert_after(d11,0), TRUE);
  109.   TEST ("d8[0] == &d10", (d8[0] == &d10), 1);
  110.   TEST ("d8[1] == &d11", (d8[1] == &d11), 1);
  111.   TEST ("d8[2] == &d9", (d8[2] == &d9), 1);
  112. }
  113.  
  114.  
  115. void test_NN_charP() {
  116.   CoolN_Node<char*,4> n4;
  117.   TEST ("CoolN_Node<char*,4> n", n4.is_leaf(), TRUE);
  118.   TEST ("n4.set(\"AAA\")", (n4.set("AAA"), strcmp (n4.get(), "AAA")), 0);
  119.   CoolN_Node<char*,4>& n5 = *(new CoolN_Node<char*,4>("BBB"));
  120.   TEST ("CoolN_Node<char*,4> n5(\"BBB\")", n5.is_leaf(), TRUE);
  121.   TEST ("n5.get()", strcmp (n5.get(), "BBB"),0);
  122.   CoolN_Node<char*,4>& n6 = *(new CoolN_Node<char*,4>(n5));
  123.   TEST ("CoolN_Node<char*,4> n6(n5)", strcmp (n5.get(), n6.get()), 0);
  124.   CoolN_Node<char*,4>& n7 = *(new CoolN_Node<char*,4>("CCC"));
  125.   TEST ("CoolN_Node<char*,4> n7(\"CCC\")", n7.is_leaf(), TRUE);
  126.   TEST ("n7.get()", strcmp (n7.get(), "CCC"), 0);
  127.   TEST ("n5.set(\"DDD\")", (n5.set("DDD"), strcmp (n5.get(), "DDD")), 0);
  128.   TEST ("n4[0] = &n5", (n4[0] = &n5, (n4[0] == &n5)), 1);
  129.   TEST ("n4.is_leaf()", n4.is_leaf(), FALSE);
  130.   TEST ("n4.insert_before(n6,0)", n4.insert_before(n6,0), TRUE);
  131.   TEST ("n4[0] == &n6", (n4[0] == &n6), 1);
  132.   TEST ("n4[1] == &n5", (n4[1] == &n5), 1);
  133.   TEST ("n4.insert_after(n7,0)", n4.insert_after(n7,0), TRUE);
  134.   TEST ("n4[0] == &n6", (n4[0] == &n6), 1);
  135.   TEST ("n4[1] == &n7", (n4[1] == &n7), 1);
  136.   TEST ("n4[2] == &n5", (n4[2] == &n5), 1);
  137. }
  138.  
  139. void test_DN_charP() {
  140.   CoolD_Node<char*,4> d4;
  141.   TEST ("CoolD_Node<char*,4> n", d4.is_leaf(), TRUE);
  142.   TEST ("d4.set(\"AAA\")", (d4.set("AAA"), strcmp (d4.get(), "AAA")), 0);
  143.   CoolD_Node<char*,4>& d5 = *(new CoolD_Node<char*,4>("BBB"));
  144.   TEST ("CoolD_Node<char*,4> d5(\"BBB\")", d5.is_leaf(), TRUE);
  145.   TEST ("d5.get()", strcmp (d5.get(), "BBB"),0);
  146.   CoolD_Node<char*,4>& d6 = *(new CoolD_Node<char*,4>(d5));
  147.   TEST ("CoolD_Node<char*,4> d6(d5)", strcmp (d5.get(), d6.get()), 0);
  148.   CoolD_Node<char*,4>& d7 = *(new CoolD_Node<char*,4>("CCC"));
  149.   TEST ("CoolD_Node<char*,4> d7(\"CCC\")", d7.is_leaf(), TRUE);
  150.   TEST ("d7.get()", strcmp (d7.get(), "CCC"), 0);
  151.   TEST ("d5.set(\"DDD\")", (d5.set("DDD"), strcmp (d5.get(), "DDD")), 0);
  152.   TEST ("d4[0] = &d5", (d4[0] = &d5, (d4[0] == &d5)), 1);
  153.   TEST ("d4.is_leaf()", d4.is_leaf(), FALSE);
  154.   TEST ("d4.insert_before(d6,0)", d4.insert_before(d6,0), TRUE);
  155.   TEST ("d4[0] == &d6", (d4[0] == &d6), 1);
  156.   TEST ("d4[1] == &d5", (d4[1] == &d5), 1);
  157.   TEST ("d4.insert_after(d7,0)", d4.insert_after(d7,0), TRUE);
  158.   TEST ("d4[0] == &d6", (d4[0] == &d6), 1);
  159.   TEST ("d4[1] == &d7", (d4[1] == &d7), 1);
  160.   TEST ("d4[2] == &d5", (d4[2] == &d5), 1);
  161. }
  162.  
  163. void test_leak () {
  164.   for (;;) {
  165.     test_NN ();
  166.     test_DN ();
  167.     test_NN_charP();
  168.     test_DN_charP();
  169.   }
  170. }
  171.  
  172. int main () {
  173.   START("CoolN_Node and CoolD_Node");
  174.   test_NN ();
  175.   test_DN ();
  176.   test_NN_charP();
  177.   test_DN_charP();
  178. #if LEAK
  179.   test_leak ();
  180. #endif
  181.   SUMMARY();
  182.   return 0;
  183. }
  184.